package databaseAcces;


/**
 * Insertin requests
 * in database
 * @version 1.0
 * @auhor <a href="mailto:maacheikh@yahoo.fr">CHEIKH MBACKE THIAM</a>
 *
*/

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

public class InsertionRequest {
	
	private Connection conecttion ;
	private Connexion conect ;
	/**
	 *Insertin request
	 *
	 * @exception SQLException
	 *
	 */
	public InsertionRequest() {

		conect = new Connexion();
		conecttion = conect.getConnexion();
		}

		/**
		 * Insertion of Candidate in database
		 *
		 * @return return true if insertion was ok
		 */
		public boolean insertCandidate (String nom_prenom,String web_site,String adresse,String telephone,
		String courriel,String date_naiss, double salaire_souhaite,String diplome,String sexe,String description,String language,int num_user) 
		{

			if (conecttion == null) return false;
			String req = "INSERT INTO Candidat(nom_prenom,web_site,adresse,telephone,courriel, date_naiss,salaire_souhaite,diplome,sexe,description,language,num_user) " +
			"VALUES('"+nom_prenom+"','"+web_site+"','"+adresse+"','"+telephone+"','"+courriel+"','"+date_naiss+"','"+salaire_souhaite+"','"+
					diplome+"','"+sexe+"','"+ description +"','"+ language+"','"+num_user+"')";
			
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Candidat déjà enregistre");
			}

		  return true;
		}
		
		public boolean updateCandidatures(int num_Ca,String nom_prenom,String web_site,String adresse,String telephone,
				String courriel,String date_naiss, double salaire_souhaite,String diplome,String sexe,String description,String language,int num_user) 
		{
			if (conecttion == null) 
				return false;

			String req = "UPDATE Candidat SET " + "nom_prenom='"+ nom_prenom+"', web_site='"+web_site+"', adresse='"+adresse+"', "
						+ "telephone='"+telephone+"', courriel='"+courriel+"', date_naiss='"+date_naiss+"', salaire_souhaite='"+salaire_souhaite+"', "
						+ "diplome='"+diplome+"', sexe='"+sexe+"', description='"+description+"', language='"+language+"' "
						+"WHERE num_Ca="+num_Ca;
		
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Ne pas mettre a jours Candidature");
			}
			
		  return true;
		}
		/**
		 * Insertion of Candidate in database
		 *
		 * @return return true if insertion was ok
		 */
		public boolean insertExperienceCandidate (int num_Ca,int num_experien,String nom_Poste_Exerce,String specialite,String domaine) {

			if (conecttion == null) return false;
			String req = "INSERT INTO Experience(num_Ca,num_experien,nom_Poste_Exerce,specialite,domaine) VALUES('"
			            +num_Ca+"','"+num_experien+"','"+nom_Poste_Exerce+"','"+specialite+"','"+domaine+"')";
			
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Client déjà enregistre");
			}
			
		  return true;
		}
		
		public boolean updateExperience(int num_Ca,int num_experien,String nom_Poste_Exerce,String specialite,String domaine)
		{
			if (conecttion == null) 
				return false;

			String req = "UPDATE Experience SET num_experien='"+num_experien+"', nom_Poste_Exerce='"+nom_Poste_Exerce+"', "
						+"specialite='"+specialite+"', domaine='" + domaine+"' "
						+ "WHERE num_Ca="+num_Ca;
			
			System.out.println(req);
			
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Ne pas mettre a jours Experience");
			}
			
		  return true;
		}
		
		
		/**
		 * Insertion of Candidate in database
		 *
		 * @return return true if insertion was ok
		 */
		public boolean insertEntreprise (String nom_En,String web_site,String adresse,String telephone,String courriel,String description, int num_user) {

			if (conecttion == null) return false;
			String req = "INSERT INTO Entreprise(nom_En,web_site,adresse,telephone,courriel,description,num_user) " +
					"     VALUES('"+nom_En+"','"+web_site+"','"+adresse+"','"+telephone+"','"+courriel+"','"+description+"','"+num_user+"')";
			
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Client déjà enregistre");
			}
			
		  return true;
		}	
		
		public boolean UpdateEntreprise (int num_En,String nom_En,String web_site,String adresse,
						String telephone,String courriel,String description, int num_user)
		{

			if (conecttion == null) 
				return false;
			String req = "UPDATE Entreprise SET nom_En='"+nom_En+"', web_site='"+web_site+"', " +"adresse='"+adresse+
							"', telephone='" + telephone+"', courriel='" +courriel +"', description='"+description+"'"
						+ "WHERE num_En="+num_En;
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Client déjà enregistre");
			}
			
		  return true;
		}	
		
		/**
		 * Insertion of poste in database
		 *
		 * @return return true if insertion was ok
		 */
		public boolean insertPoste (String titre,String specialite,String domaine,double salaire_propose
						,String experience_requis,String lieu_travail,String niveau,String description,
						int num_En,String date_limite) 
		{
			if (conecttion == null) 
				return false;
			String req = "INSERT INTO Poste(titre,specialite,domaine,salaire_propose,experience_requis,lieu_travail,niveau,description,num_En,date_limite) "
						+ "VALUES('"+titre+"','"+specialite+"','"+domaine+"','"+salaire_propose+"','"+experience_requis+"','"+lieu_travail+"','"+
									niveau+"','"+description+"','"+num_En+"','"+date_limite+"')";
		
			try {
				Statement st = conecttion.createStatement();
				 st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Poste déjà enregistre");
			}

		  return true;
		}
		
		public boolean updatePoste (int num_En,String titre,String specialite,String domaine,double salaire_propose
				,String experience_requis,String lieu_travail,String niveau,String description,String date_limite) 
		{
			if (conecttion == null) 
				return false;
			String req = "UPDATE Poste SET titre='"+titre+"', specialite='"+specialite+"', " +"domaine='"+domaine+
					"', salaire_propose='" + salaire_propose +"', experience_requis='" +experience_requis 
					 +"', lieu_travail='"+lieu_travail+"', niveau='"+niveau+"', description='"+description+"', date_limite='" + date_limite+"' "
				+ "WHERE num_En='"+num_En+"'";
			
			try {
				Statement st = conecttion.createStatement();
				st.executeUpdate(req);
				st.close();
				return true;
			}
			catch (SQLException se) {
				System.out.println("Poste déjà enregistre");
			}

			return true;
		
		}

		
}
